package com.youth.fund.hk.hostManager.manager.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.youth.fund.hk.hostManager.lucene.datamodel.ContentModel;
import com.youth.fund.hk.hostManager.lucene.service.SearchService;

@Controller
@RequestMapping("/json/search")
public class SearchWebServiceController 
{
	@Autowired
	@Qualifier("SearchService")
	private SearchService service;
	
	
	@RequestMapping(value="/{keyword}.json",method=RequestMethod.GET)
	public @ResponseBody Object search(@PathVariable String keyword,Model model) 
	{
		//在server。xml中加入<Connector URIEncoding="UTF-8" connectionTimeout="20000" executor="tomcatThreadPool" port="80" protocol="HTTP/1.1" redirectPort="8443"/>
		//解决了编码问题
//		try {
//			keyword = new String(keyword.getBytes("ISO8859_1"),"UTF-8");
//		} catch (UnsupportedEncodingException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		List<ContentModel> jsonList = service.queryIndex(keyword);
		
		for(ContentModel cm:jsonList)
		{
			this.getKeywordRelated(cm, keyword);
		}
		
		model.addAttribute("list", jsonList);

		return model;
	}
	
	private void getKeywordRelated(ContentModel model,String keyword)
	{
		
	}
}
